# _*_ coding: utf-8 _*_
"""
Time:     2022/3/15 23:36
Author:   suhong
Version:  V 0.1
File:     1.py
"""
from selenium import webdriver

import time

from selenium.webdriver.common.action_chains import ActionChains
#定位谷歌浏览器
driver = webdriver.Chrome()

#打开百度
driver.get("https://www.baidu.com/")

#设置浏览器大小  全屏
driver.maximize_window()

def login():    #用户登录
    login = driver.find_element_by_link_text("登录")  #查询登录按钮，点击登录
    login.click()
    time.sleep(4)   #等待四秒

    # userlogin = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_11__footerULoginBtn"]')
    # userlogin.click()   #找到用户登录按钮
    # time.sleep(1)

    username = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_11__userName"]')
    username.click()
    username.send_keys('你的账号')   #找到用户名输入
    time.sleep(1)

    password = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_11__password"]')
    password.click()
    password.send_keys('你的密码')   #找到密码输入
    time.sleep(1)

    loginBtn = driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_11__submit"]')
    loginBtn.click()   #找到登录按钮，进行登录
    time.sleep(4)   #等待四秒

# def logout():   #退出登录
#     userImg = driver.find_element_by_xpath('//*[@id="s-top-username"]/span[2]')   #找到头像位置
#     ActionChains(driver).move_to_element(userImg).perform() #鼠标悬停
#     time.sleep(1)
#
#     userLogout = driver.find_element_by_xpath('//*[@id="s-user-name-menu"]/a[4]')   #找到退出登录按钮
#     userLogout.click()
#     time.sleep(4)
#
#     ensureBtn = driver.find_element_by_xpath('//*[@id="dialog_con_wrap"]/div[3]/div[1]/span[1]')
#     ensureBtn.click()


if __name__ == "__main__" :
    login()    #登录
    # logout()    #退出登录


